package org.myspringframework.aop.framework.adapter;

import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.myspringframework.aop.Advisor;
import org.myspringframework.aop.MethodBeforeAdvice;

//前置通知的适配器，负责将前置通知advice转换为环绕通知methodInterceptor
//在代理对象执行方法时发生转换
public class MethodBeforeAdviceAdapter implements AdvisorAdapter{

    //是否进行转换
    @Override
    public boolean supportsAdvice(Advice advice) {
        return (advice instanceof MethodBeforeAdvice);
    }

    //进行转换
    @Override
    public MethodInterceptor getInterceptor(Advisor advisor) {
        MethodBeforeAdvice methodBeforeAdvice = (MethodBeforeAdvice) advisor.getAdvice();
        return new MethodBeforeAdviceInterceptor(methodBeforeAdvice);
    }
}
